//
//  ChatTextCell.swift
//  
//
//  Created by Author on 2023/3/14.
//  Copyright © 2023 Author. All rights reserved.
//

import UIKit

class ChatTextCell: BaseTableViewCell {
    static let msgFont = UIFont.systemFont(ofSize: 15)
    static let cellID = NSStringFromClass(ChatTextCell.classForCoder())
    private lazy var tap :UITapGestureRecognizer = {
        let tap = UITapGestureRecognizer(target: self, action: #selector(mesLabelClick))
        tap.isEnabled = false
        return tap
    }()
    var clickTextClosure:((_ textModel: TextMsgModel)->Void)?
    private lazy var msgLabel :UILabel = {
        let label = UILabel()
        label.textColor = .black.withAlphaComponent(12)
        label.text = ""
        label.numberOfLines = 0
        label.font = Self.msgFont
        label.addGestureRecognizer(tap)
        label.isUserInteractionEnabled = true
        label.preferredMaxLayoutWidth = SCREENW - 134
        let tap = UITapGestureRecognizer(target: self, action: #selector(mesLabelClick))
        label.addGestureRecognizer(tap)
        return label
    }()
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func setupUI(){
        super.setupUI()
        
        wrapView.addSubview(msgLabel)
        
    }
    override func updateData() {
        guard let msg = msg, let textModel = msg as? TextMsgModel else{return}
        super.updateData()
        msgLabel.text = textModel.title
        msgLabel.snp.makeConstraints { make in
            make.top.equalTo(8)
            make.trailing.equalToSuperview()
            make.leading.equalToSuperview()
            make.bottom.equalToSuperview().offset(-10)
        }
        
        
        
    }
    //MARK: Action
    @objc private func mesLabelClick(){
        guard let textModel = msg as? TextMsgModel else{return}
//        self.clickTextClosure?(textModel) 原来的回调方案
        self.eventCallback?(.CellTapText,textModel)
        
    }
    
    
    
    
    
    
}
